package com.example.test.service;

import com.example.test.entity.Notice;
import com.example.test.entity.Product;
import com.example.test.mapper.NoticeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

@Service
public class NoticeService {
     @Autowired
     private  NoticeMapper noticeMapper;

     public List<Notice> getAllNotices() {
        return noticeMapper.selectAll();
    }

      public Notice updateNotice(int id, Notice updatedNotice ) throws IOException {
         Notice notice = noticeMapper.getNoticeById(id);
         if (notice != null) {
           notice.setText(updatedNotice.getText());
           notice.setIfplay(updatedNotice.getIfplay());
           noticeMapper.updateNotice(notice);
        }
        return notice;
    }
    public void deleteNotice(int id) {
        Notice notice = noticeMapper.getNoticeById(id);
        if (notice != null) {
            noticeMapper.deleteNotice(id);
        }
    }
}
